﻿using BlogDemo.Core.Entities;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;

namespace BlogDemo.Infrastructure.Database
{
    public class SqlSugarContext
    {
        public readonly SqlSugarClient _client;
        public SqlSugarContext(string connString)
        {
            if (_client == null)
            {
                _client = new SqlSugarClient(new ConnectionConfig()
                {
                    ConnectionString = connString,
                    DbType = DbType.Sqlite,
                    IsAutoCloseConnection = true,
                    InitKeyType = InitKeyType.SystemTable
                });
            }
        }

        public ISugarQueryable<Post> Post
        {
            get
            {
                return _client.Queryable<Post>();
            }
        }
    }
}
